# -*- coding: utf-8 -*-


from multiprocessing import Process, Lock
def get(name):
    with open('data.txt', 'wt', encoding='utf-8') as f:
        f.write(str(name))
    with open('data.txt', 'r', encoding='utf-8') as f:
        data = f.read()
        print(data)     # 加锁就是0-10每个都有，不加锁可能被覆盖重复某个数字
def task(name, mutex):
    mutex.acquire()  # 获取锁 串行
    get(name)
    mutex.release()  # 释放锁
if __name__ == '__main__':
    mutex = Lock()
    for i in range(10):
        p = Process(target=task, args=(i, mutex))
        p.start()
